<template>
  <div class="userLogin">
    <!-- 常规 账号登录页面 -->

    <el-form-item label="用户名" prop="username">
      <el-input
        type="text"
        v-model="loginForm.username"
        autocomplete="off"
      ></el-input>
    </el-form-item>
    <el-form-item label="密码" prop="password">
      <el-input
        type="password"
        v-model="loginForm.password"
        autocomplete="off"
      ></el-input>
    </el-form-item>
    <el-form-item label="验证码" prop="captcha">
      <el-input
        v-model="loginForm.captcha"
        maxlength="5"
        class="captcha"
        @keydown.native.enter="submitForm('loginForm')"
      ></el-input>
      <span class="captcha_svg" v-loading="loading">
        <i v-html="captcha" @click="getCaptcha"></i>
      </span>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm('loginForm')">
        提交
      </el-button>
    </el-form-item>

    <!-- 手机登陆图标按钮 -->
    <!-- <el-form-item > -->
    <div class="sms">
      <!-- <svg calss="icon" aria-hidden="true">
                    <use xlink:href="#icon-iphone"></use>
                </svg> -->
      <svg class="icon" aria-hidden="true">
        <use xlink:href="#icon-shouji-iphone12-zhengmian"></use>
      </svg>
      <a
        href="javascript:;"
        @click="$emit('changeSmsType')"
        style="color: #fff; font-size: 16px"
      >
        切换短信登录
      </a>
    </div>
    <!-- </el-form-item> -->
  </div>
</template>

<script>
import * as api from "@/api/users";
export default {
  mounted() {},
  created() {
    this.getCaptcha();
  },
  // props:['loginForm'],
  data() {
    return {
      loading: false, //声明一个字段，控制动画加载
      captcha: "", //验证码
      isSmsLogin: true, //控制切换短信登录
      loginForm: {
        //登入输入的数据
        username: "",
        password: "",
        captcha: "",
      },
    };
  },
  watch: {
    loginForm: {
      handler(newVal) {
        // console.log(newVal)
        // 传递一个自定义事件syncLoginForm
        this.$emit("syncLoginForm", newVal);
      },
      deep: true,
    },
  },
  methods: {
    submitForm(formName) {
      this.$emit("submit");
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    //封装一个获取验证码的方法
    getCaptcha() {
      //打开加载动画
      this.loading = true;
      api.getCaptcha().then((res) => {
        // console.log(res)
        this.captcha = res.data.img;
        //关闭加载动画
        this.loading = false;
      });
    },
  },
};
</script>
<style lang="less" scoped>
.userLogin {
  // background: rgba(226, 131, 163, 0.3);
  // border:1px solid rgba(0, 0, 0, .3);
  width: 100%;
  display: flex;
  align-items: center;
  // justify-content: center;
  flex-direction: column;
  /deep/ .el-form-item__label {
    width: 75px !important;
    color: #fff !important;
    margin-left: -20px;
    font-size: 16px;
    // font-weight: 900;
  }
  /deep/ .el-input {
    margin-left: -46px;
    width: 260px;
    border-radius: 8px;
  }
  .captcha {
    background: #fff;
    width: 100px !important;
    border-top-left-radius: 4px !important;
    border-bottom-left-radius: 4px !important;
  }
  .captcha_svg {
    // display: inline-block;
    float: right;
    width: 160px;
    height: 40px;
    background-color: #fff;
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
    i {
      cursor: pointer;
    }
  }
  h1 {
    color: #fff;
    text-align: center;
    margin: 0 0 60px 0;
  }

  .el-button {
    background: linear-gradient(90deg, #1596fb, #002dff);
    width: 260px;
    margin-right: 46px;
  }
}

a {
  // position: absolute;
  right: 364px;
}
</style>
